#include "2d.h"

void arr2d_init(Array2D *arr, int height, int width) {
    arr->data = (int*)malloc(width * height * sizeof(int));
	if (arr->data == NULL) {
		printf("sorry, memory error");
	}
    arr->width = width;
	arr->height = height;
}
int arr2d_get(Array2D *arr, int i, int j) {
    return arr->data[j + i * arr->width];
}
void arr2d_put(Array2D *arr, int i, int j, int value) {
    arr->data[j + i * arr->width] = value;
}
void arr2d_delete(Array2D *arr) {
	free(arr->data);
}
int * arr2d_resize(Array2D *arr, int i, int j) {
	if (i > arr->height && j > arr->width)
		return arr->data = (int*)realloc(arr->data, width * height * sizeof(int));
	else {
		int a, b;
		Array2D new_arr;
		arr2d_init(new_arr, i, j);
		for(a = 0, a < height, a++) {
			for(b = 0, b < width, b++) {
				arr2d_put(Array2d *arr, i, j, arr2d_get(arr, i, j));
			}
		}
	}
}